using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.AnalysisServices.AdomdClient;

namespace BILab.Technical.BI.Util
{
    public class MDUtil
    {
        public Dictionary<int, Headers> getHeaders(OlapInfoAxis axisInfo, Axis axis)
        {
            Dictionary<int, Headers> dict = new Dictionary<int, Headers>();
            bool isNew = false;

            Headers previousNewHeaders = new Headers();

            for (int i = 0; i < axisInfo.Hierarchies.Count; i++)
            {
                Header hdr = new Header();
                hdr.Caption = null;
                hdr.IsNew = true;

                previousNewHeaders.Add(hdr);
            }

            for (int position = 0; position <  axis.Positions.Count; position++)
            {
                // Step 1
                isNew = false;
                Headers tempHeaders = new Headers();
                for (int hierCount = 0; hierCount <  axisInfo.Hierarchies.Count-1; hierCount++)
                {
                    Header hdr = new Header();
                    hdr.Caption =  axis.Positions[position].Members[hierCount].Caption;
                    if ( !hdr.Caption.Equals(previousNewHeaders[hierCount].Caption))
                    {
                        isNew = true;
                        hdr.IsNew = true;
                    }
                    tempHeaders.Add(hdr);
                }
                // Step 2
                Header lastHeader = new Header();
                lastHeader.Caption = axis.Positions[position].Members[axisInfo.Hierarchies.Count - 1].Caption;
                lastHeader.IsNew = true;
                tempHeaders.Add(lastHeader);

                // Step 3
                if (isNew)
                {
                    dict.Add(position, tempHeaders);
                    previousNewHeaders = tempHeaders;
                }
            }
            return dict;


        }
      } // MdUtil

}
